package org.lanqiao.lg.dao.impl;

import java.util.List;
import java.util.Map;

import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.MapListHandler;
import org.apache.commons.dbutils.handlers.ScalarHandler;
import org.lanqiao.bean.Company;
import org.lanqiao.lg.dao.CompanyDao;
import org.lanqiao.tools.BaseDao;

public class CompanyDaoImpl extends BaseDao implements CompanyDao {

//	@Override 通过id查询公司信息
	public Company selectCompanyById(Integer id) {
		try {
			return query.query("select * from company where id=?", new BeanHandler<Company>(Company.class), id);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

//	@Override 注册添加公司帐号信息
	public Integer insertCompanyNum(Company info) {
		try {
			return query.update("INSERT INTO company(num,pwd,sateIds,date) VALUES(?,?,1,NOW())", info.getNum(),
					info.getPwd());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

//	@Override 注册添加公司信息
	public Integer insertCompanyName(Company info) {
		try {
			return query.update(// and sateIds=1 可加在sql语句后面
					"UPDATE company SET fullName=?,shortName=?,com=?,address=?,field=?,introductionS=?,number=?,period=?,logId=?,sateIds=2 WHERE id=?",
					info.getFullName(), info.getshortName(), info.getCom(), info.getAddress(), info.getField(),
					info.getIntroductionS(), info.getNumber(), info.getPeriod(), info.getLogId(), info.getId());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

//	@Override 查询公司id
	public Integer selectCompanyId(Company info) {
		try {
			return query.query("select id from company where num=? and pwd=? ", new ScalarHandler<Integer>(), info.getNum(),info.getPwd());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

//	@Override 添加/更新公司标签id集合
	public Integer insertCompanyLabel(Company info) {
		try {
			return query.update("UPDATE company SET labelId=? WHERE id=? ", info.getLabelId(),info.getId());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

//	@Override 通过帐号密码登录
	public Long CompanyLogin(String num, String pwd) {
		try {
			return query.query("select COUNT(\"com\") from company where num=? AND pwd=?", new ScalarHandler<Long>(), num,
					pwd);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

//	@Override 添加/更新公司详细介绍
	public Integer insertCompanyInL(Integer id,String info) {
		try {
			return query.update("UPDATE company SET introductionL=? WHERE id=? ", info,id);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

//	@Override 查询该公司发布有效的职位
	public List<Map<String, Object>> selectPositionByCId(Integer cid) {
		try {
			return query.query("select * from position where companyid=? and stateId=3 ORDER BY date DESC LIMIT 0,4", new MapListHandler(),cid);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

//	@Override 查询该公司下线的的职位
	public List<Map<String, Object>> selectOldPositionByCId(Integer cid) {
		try {
			return query.query("select * from position where companyid=? and stateId=4 ORDER BY date DESC LIMIT 0,4", new MapListHandler(),cid);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

//	@Override	根据职位id 查到 投递简历 状态是2 待定的
	public List<Map<String, Object>> selectResByPId2(Integer pid) {
		try {
			return query.query("SELECT * FROM positionToResume WHERE positionId=? AND stateId=2", new MapListHandler(),pid);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

//	@Override	根据职位id 查到 投递简历 状态是3 通知面试
	public List<Map<String, Object>> selectResByPId3(Integer pid) {
		try {
			return query.query("SELECT * FROM positionToResume WHERE positionId=? AND stateId=3", new MapListHandler(),pid);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

//	@Override	根据职位id 查到 投递简历 状态是4 不合适
	public List<Map<String, Object>> selectResByPId4(Integer pid) {
		try {
			return query.query("SELECT * FROM positionToResume WHERE positionId=? AND stateId=4", new MapListHandler(),pid);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

}
